package com.feisuanyz.lyweb01.controller;

import com.feisuanyz.lyweb01.constant.ResultCodeConstant;
import com.feisuanyz.lyweb01.pojo.domain.NewsDO;
import com.feisuanyz.lyweb01.pojo.dto.CreateGroup;
import com.feisuanyz.lyweb01.pojo.dto.NewsDTO;
import com.feisuanyz.lyweb01.pojo.dto.RestResult;
import com.feisuanyz.lyweb01.pojo.dto.UpdateGroup;
import com.feisuanyz.lyweb01.pojo.query.NewsQuery;
import com.feisuanyz.lyweb01.pojo.query.QueryGroup;
import com.feisuanyz.lyweb01.pojo.vo.PageResult;
import com.feisuanyz.lyweb01.service.NewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 新联资讯
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Tag(name = "新联资讯")
@RequestMapping("news")
@RestController
public class NewsController {

    @Autowired
    private NewsService newsService;

    /**
     * 接口名称: 获取新联资讯列表
     *
     * @param newsQuery 新闻查询参数对象
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @Operation(summary = "接口名称: 获取新联资讯列表")
    public RestResult<PageResult<NewsDO>> getNewsList(@Validated(QueryGroup.class) NewsQuery newsQuery) {
        PageResult<NewsDO> result = newsService.getNewsList(newsQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 获取新联资讯详情
     *
     * @param newsQuery 新闻查询参数对象
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "接口名称: 获取新联资讯详情")
    public RestResult<NewsDO> getNewsInfo(@Validated(QueryGroup.class) NewsQuery newsQuery) {
        NewsDO result = newsService.getNewsInfo(newsQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 搜索新联资讯
     *
     * @param newsQuery 新闻查询参数对象
     * @return
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @Operation(summary = "接口名称: 搜索新联资讯")
    public RestResult<PageResult<NewsDO>> searchNews(@Validated(QueryGroup.class) NewsQuery newsQuery) {
        PageResult<NewsDO> result = newsService.searchNews(newsQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 添加新联资讯
     *
     * @param newsDTO 新闻数据传输对象
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "接口名称: 添加新联资讯")
    @ResponseBody
    public RestResult<Boolean> addNews(@RequestBody @Validated(CreateGroup.class) NewsDTO newsDTO) {
        Boolean result = newsService.addNews(newsDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 修改新联资讯
     *
     * @param newsDTO 新闻数据传输对象
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "接口名称: 修改新联资讯")
    @ResponseBody
    public RestResult<Boolean> updateNews(@RequestBody @Validated(UpdateGroup.class) NewsDTO newsDTO) {
        Boolean result = newsService.updateNews(newsDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 接口名称: 删除新联资讯
     *
     * @param newsQuery 新闻查询参数对象
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "接口名称: 删除新联资讯")
    public RestResult<Boolean> deleteNews(@Validated(QueryGroup.class) NewsQuery newsQuery) {
        Boolean result = newsService.deleteNews(newsQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
